# coding=UTF-8
import werobot
from werobot import client
from werobot.replies import TextReply
import bilibili  # B站视频解析
import hitokoto  # 随机鸡汤
import wantWords  # 近义词
import translate  # 翻译
import weather  # 查询天气
import genshin  # 原神历史记录查询

robot = werobot.WeRoBot(token='wxserver')
robot.config["APP_ID"] = "wxb6e0e7929e99101c"
robot.config["APP_SECRET"] = "097fd3f4241e9055b095a1180b5003fa"
client = robot.client

# @robot.text 修饰的 Handler 只处理文本消息


@robot.text
def echo(message):
    # 天气查询功能
    if "天气" in message.content:
        return weather.get(message.content)

    # B站链接或BV号解析
    elif bilibili.check(message.content) == True:
        return bilibili.analysis(message.content)

    # hitokoto随机鸡汤
    elif 'hitokoto' in message.content:
        return hitokoto.get()

    # wantWords近义词
    elif '的近义词' in message.content:
        return wantWords.get(message.content)

    # 翻译（有道API）
    elif '的翻译' in message.content:
        return translate.get(message.content)

    elif '#/log' in message.content:
        return genshin.get(message.content)

    else:
        str = message.content.replace('我', '我我').replace('你', '我').replace(
            '我我', '你').replace('吗', '').replace('？', '').replace('?', '')
        return str


# @robot.image 修饰的 Handler 只处理图片消息
@robot.image
def img(message):
    return message.img


@robot.text
def first(message, session):
    if 'first' in session:
        return '你之前给我发过消息'
    session['first'] = True
    return '你之前没给我发过消息'


# 让服务器监听在 0.0.0.0:80
robot.config['HOST'] = '0.0.0.0'
robot.config['PORT'] = 80
robot.run()
